package com.wuyong.chapter7;


import com.wuyong.chapter4.LinkedList;

/**
 * 链表实现set
 * @param <E>
 */
public class LikedListSet<E> implements Set<E>{

    private LinkedList<E> linkedList;

    public LikedListSet() {
        linkedList = new LinkedList<>();
    }
    @Override
    public void add(E e) {
        if (!linkedList.contain(e))
            linkedList.addFirst(e);
    }

    @Override
    public void remove(E e) {
        linkedList.removeElement2(e);
    }

    @Override
    public boolean contains(E e) {
        return linkedList.contain(e);
    }

    @Override
    public int getSize() {
        return linkedList.getSize();
    }

    @Override
    public boolean isEmpty() {
        return linkedList.isEmpty();
    }

    @Override
    public String toString() {
        return linkedList.toString();
    }
}
